/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MyBufferedReader {

    private String filename;
    private File file;
    private FileReader fr;
    private BufferedReader br;
    private Integer ip = 0;
    private String paths = "/media/jef_stuff/Documents/NetBeansProjects/jefox/file system/";
    public static Hashtable<String, Integer> files_list = new Hashtable();
    public LinkedList<Integer> file_queue = new LinkedList();

    public MyBufferedReader(String fileName){
        fileName = paths + fileName;
        filename = fileName;
        file = new File (fileName);
        try{
            fr = new FileReader(file);
            br = new BufferedReader(fr);
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        if(files_list.containsKey(fileName)){
            for(int i = 0; i < files_list.get(filename);i++)
                try {
                br.readLine();
            } catch (IOException ex) {
                Logger.getLogger(MyBufferedReader.class.getName()).log(Level.SEVERE, null, ex);
            }
            ip = files_list.get(filename);
        }else
            files_list.put(fileName, ip);
        
    }

    public String readLine()throws IOException{
        String s = br.readLine();
        ip++;
        if(s == null)
            s = "";
        else
            if (s.length() == 0)
            s = " ";
        return s;
    }

    public void closeFile()throws IOException{
            fr.close();
            br.close();
            files_list.remove(filename);
    }
}